Ext.define('pm.view.Project.ProjectMembers' ,{
    extend: 'Ext.grid.Panel',
    //extend: 'Ext.view.View',
    alias : 'widget.ProjectMembersList',

    store: 'UsersOfProject',
    
    emptyText: 'No projects',
    projectRecord: null,

    viewConfig: {
        plugins: [
            {
                ddGroup: 'GridExample2',
                ptype: 'gridviewdragdrop',
            },
        ]
    },
    hideHeaders: true,
    frameHeader: false,
    width: '100%',
    height: '100%',

    initComponent: function() {

        this.tooltip = Ext.create('Ext.tip.ToolTip', {})

        this.columns = [
            {header: '',  dataIndex: 'user_name', xtype:'templatecolumn', tpl:'{user_name} ({senority})', width: '100%'},
        ];

        this.callParent(arguments);
    },

    listeners: {
        render:  function(v) {
            this.getView().on('beforedrop', function(node, data, dropRec, dropPosition) {
                console.log('before drop on members list of project')
                if(data.records.length) {
                    return v.dragItemToTarget(data.records[0], v.projectRecord)
                }
                return false
            })
        },
    },

    dragItemToTarget: function(item, target) {
        console.log('drag ' + item.get('name') + ' on ' + target.get('name') + ', dropped class=' + item.self.getName())

        if(item.self.getName() == 'pm.model.Personal') {
            this.fireEvent('addUserToProject', item, target)
            return false
        }
    },

    showToolTip: function(record, e) {
        var tip = this.tooltip
        tip.show()
        tip.setPosition(e.getXY())
        var txt = ''
        tip.update('Over company "' + txt + '"');
    }

});